#!/bin/sh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

#
# Reset netmask and broadcast address whenever new information is
# availabe from NIS.
#

. /lib/svc/share/smf_include.sh

#
# In a shared-IP zone we need this service to be up, but all of the
# work it tries to do is irrelevant (and will actually lead to the
# service failing if we try to do it), so just bail out. 
# In the global zone and exclusive-IP zones we proceed.
#
smf_configure_ip || exit $SMF_EXIT_OK

#
# wait_nis
# Wait up to 5 seconds for ypbind to obtain a binding.
#
wait_nis ()
{
	for i in 1 2 3 4 5; do
		server=`/usr/bin/ypwhich 2>/dev/null`
		[ $? -eq 0 -a -n "$server" ] && return 0 || sleep 1
	done
	return 1
}

#
# Reset the netmask and broadcast address for our network interfaces.
# Since this may result in a name service lookup, we want to now wait
# for NIS to come up if we previously started it.
#
domain=`/usr/bin/domainname 2>/dev/null`

[ -z "$domain" ] || [ ! -d /var/yp/binding/$domain ] || wait_nis || \
    echo "WARNING: Timed out waiting for NIS to come up" >& 2

#
# Re-set the netmask and broadcast addr for all IP interfaces.  This
# ifconfig is run here, after waiting for name services, so that
# "netmask +" will find the netmask if it lives in a NIS map. The 'D'
# in -auD tells ifconfig NOT to mess with the interface if it is
# under DHCP control
#
/usr/sbin/ifconfig -auD4 netmask + broadcast +

# Uncomment these lines to print complete network interface configuration
# echo "network interface configuration:"
# /usr/sbin/ifconfig -a
